
//
//  UIBarButtonItem+Extension.swift
//  斯威夫特微博
//
//  Created by youyoumacmini3 on 2017/7/3.
//  Copyright © 2017年 youyoumacmini3. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    
    /// 创建 UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮，如果是加上箭头
    convenience init(title: String, fontSize: CGFloat, target: Any, action:Selector, isBack :Bool = false) {
        
        let btn = UIButton(title: title, size: fontSize, nomalColor: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), highlightedColor: #colorLiteral(red: 0.9607843161, green: 0.7058823705, blue: 0.200000003, alpha: 1))
        
        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named:imageName), for: UIControlState(rawValue:0))
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
        
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        //self.init 实例化 UIBarButtonItem
        self.init(customView:btn)
        
    }
    
    
}
